package com.jinzecloud.reportapproval.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jinzecloud.reportapproval.bean.ConsistencyCheck;
import com.jinzecloud.reportapproval.enums.StateEnum;
import com.jinzecloud.reportapproval.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jinzecloud.reportapproval.bean.DeepStabilityRecord;
import com.jinzecloud.reportapproval.service.DeepStabilityRecordService;
import com.jinzecloud.reportapproval.utils.PageUtils;
import com.jinzecloud.reportapproval.utils.R;



/**
 * 
 *
 * @author æ­å°
 * @email 1971240051@qq.com
 * @date 2024-12-03 19:14:56
 */
@RestController
@RequestMapping("reportapproval/deepstabilityrecord")
public class DeepStabilityRecordController {
    @Autowired
    private DeepStabilityRecordService deepStabilityRecordService;
    @Autowired
    private AdminService adminService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("reportapproval:deepstabilityrecord:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = deepStabilityRecordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("reportapproval:deepstabilityrecord:info")
    public R info(@PathVariable("id") Long id){
		DeepStabilityRecord deepStabilityRecord = deepStabilityRecordService.getById(id);

        return R.ok().put("deepStabilityRecord", deepStabilityRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("reportapproval:deepstabilityrecord:save")
    public R save(@RequestBody DeepStabilityRecord deepStabilityRecord){
        QueryWrapper<DeepStabilityRecord> temp = new QueryWrapper<DeepStabilityRecord>().eq("project_num", deepStabilityRecord.getProjectNum());
        List<DeepStabilityRecord> list = deepStabilityRecordService.list(temp);
        if(list.size()>0){
            return R.error("此编号已存在,请勿重复添加");
        }
        deepStabilityRecord.setAuditStatus(String.valueOf(StateEnum.UN_SUBMIT.getState())).setWordPath("").setPdfPath("");
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        deepStabilityRecord.setCreatorId(String.valueOf(adminService.getIdByName(authentication.getName())));
        deepStabilityRecordService.save(deepStabilityRecord);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("reportapproval:deepstabilityrecord:update")
    public R update(@RequestBody DeepStabilityRecord deepStabilityRecord){
		deepStabilityRecordService.updateById(deepStabilityRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("reportapproval:deepstabilityrecord:delete")
    public R delete(@RequestBody Long[] ids){
		deepStabilityRecordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 生成word
     */
    @RequestMapping("/createPdf/{id}")
    public String createWord(@PathVariable Integer id){
        return deepStabilityRecordService.createPdf(id);
    }
}
